<template>
  <div class="container">
    <uv-steps current="1" v-if="showSteps">
      <uv-steps-item title="支付成功"></uv-steps-item>
      <uv-steps-item title="报名信息(驳回)" v-if="params.status==1 && params.rejectMsg"></uv-steps-item>
      <uv-steps-item title="报名信息审核中" v-else></uv-steps-item>
      <uv-steps-item title="报名成功"></uv-steps-item>
    </uv-steps>

    <view class="wrap">
      <view class="cellGroup" v-if="params.status==1 && params.rejectMsg">
        <view class="cell">
          <view class="label fz14">驳回原因</view>
          <uv-text type="error" :text="params.rejectMsg"></uv-text>
        </view>
      </view>

      <view class="cellGroup" v-if="params.invoicing_Info && params.invoicing_Info.ycyy">
        <view class="cell">
          <view class="label fz14">开票失败原因</view>
          <uv-text type="error" :text="params.rejectMsg"></uv-text>
        </view>
      </view>

      <view class="cellGroup">
        <view class="title bold">课程内容</view>
        <view class="cell">
          <view class="label fz14">报名课程</view>
          <view class="desc fz12">{{courseInfo.name}}</view>
        </view>

        <view class="cell">
          <view class="label fz14">课程内容</view>
          <div class="fz12 desc" v-for="(item, index) in info.selectLesson" :key="index">{{item.name}}</div>
        </view>

        <view class="cell flex alignCenter justifyBetween">
          <view class="label fz14">课程金额</view>
          <div class="fz12 desc errorText">¥{{params.price}}</div>
        </view>
      </view>

      <view class="cellGroup">
        <view class="title bold">报名资料</view>
        <view class="cell  alignCenter justifyBetween" :class="{ 'flex': canFlex(item.label) }" v-for="(item, index) in descriptions" :key="index">
          <view class="label fz14">{{label_format(item.label)}}</view>
          <view style="margin-top:10px" v-if="['certificate_scancopy','identification_scancopy'].includes(item.label)">
            <view v-if="item.value">
              <view v-if="proxy.$utils.isString(item.value)">
                <view v-for="(el, idx) in item.value.split(',')" :key="idx">
                  <uv-link :href="el" :text="el" color="#458CC1"></uv-link>
                </view>
              </view>
              <view v-else-if="proxy.$utils.isArrayOrJsonArray(item.value)">
                <view v-for="(el, idx) in item.value" :key="idx">
                  <uv-link :href="el.path" :text="el.name" color="#458CC1"></uv-link>
                </view>
              </view>
            </view>
          </view>
          <view class="desc fz12" v-else>{{item.value}}</view>
        </view>
      </view>

      <view class="cellGroup">
        <view class="cell" v-for="(item, index) in info.relationList" :key="index">
          <view class="label fz14">{{item.title}}</view>
          <div v-if="item.type=='image'" style="margin-top:10px">
            <image :src="item.value" mode="widthFix" />
          </div>
          <div v-else-if="['templateFile','file'].includes(item.type)">
            <view v-for="(el, idx) in item.value" :key="idx" style="margin-top:10px">
              <!-- #ifdef MP-WEIXIN -->
              <view class="flex alignCenter">
                <uv-text type="primary" :text="el.name" decoration="underline" @click="proxy.$auth.openDocument(el.path)"></uv-text>
                <view @click="proxy.$auth.saveFile(el.path)">
                  <uv-icon name="download"></uv-icon>
                </view>
              </view>
              <!-- #endif -->

              <!-- #ifdef H5 -->
              <uv-link :href="el.path" :text="el.name" :under-line="true"></uv-link>
              <!-- #endif -->
            </view>
          </div>
        </view>
      </view>
    </view>

    <uv-back-top :scroll-top="scrollTop"></uv-back-top>
  </div>
</template>

<script setup lang="ts">
const { proxy } = getCurrentInstance();
import useCounterStore from "@/stores/counter";
const counter = useCounterStore();
const instance = getCurrentInstance();

let params = ref({});
let dicts = ref([]); //字典数据
let showSteps = ref(false); //是否显示步骤
let descriptions = ref([]);
let info = ref({});
let id = "";
let courseInfo = ref({});
let scrollTop = ref(0);

onLoad((e) => {
  id = e.id;
  getInfo();
});

onPageScroll((e) => {
  scrollTop.value = e.scrollTop;
});

let customStyleBtn = computed(() => {
  return {
    height: "30px",
  };
});

function canFlex(label) {
  let a = [
    "certificate_scancopy",
    "identification_scancopy",
    "conditions-3rd-grade",
  ].includes(label);
  return !a;
}

async function getInfo() {
  let row = await proxy.$apis.orderAction({
    type: "details",
    data: { _id: id },
  });

  courseInfo.value = await proxy.$apis.webCourse({
    type: "details",
    data: { _id: row.curriculum_id },
  });
  params.value = proxy.$utils.deepcopy(row);
  console.log("params.value", params.value);
  getDict();
  info.value = row.approvalContent;
  console.log("info.value", info.value);
  if (row.status == 1) showSteps.value = true;
  descriptions.value = proxy.$utils.objTurnArr(info.value.model);
}

async function getDict() {
  let { data } = await proxy.$apis.getDict({
    type: "details",
    data: { code: "user_info" },
  });
  dicts.value = data;
}

function label_format(e) {
  if (!dicts.value.length) return;
  let index = proxy.$utils.findIndexByField(dicts.value, "dict_code", e);
  if (index != -1) return dicts.value[index].dict_label;
}
</script>



<style lang="scss" scoped>
.container {
  padding: 10px 0;
  .wrap {
    padding: 0 15px;
    margin-top: 15px;
  }
  .cellGroup {
    .title {
      padding: 15px 0;
      font-weight: bold;
    }
    .cell {
      margin-bottom: 15px;
      .label {
        font-weight: bold;
      }
      .desc {
        margin-top: 3px;
      }
      .errorText {
        color: #f56c6c;
      }
    }
  }
}
</style>






